const app = getApp()
import util from '../../utils/util'
import {
  AdminLogin
} from '../../config/api'


Page({

  /**
   * 页面的初始数据
   */
  data: {
    username: '',
    password: '',
    baseImgUrl:app.globalData.baseImgUrl
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  inputName(e) {
    console.log('用户', e.detail.value)
    this.setData({
      username: e.detail.value
    })
  },

  inputPassword(e) {
    this.setData({
      password: e.detail.value
    })
  },

  bindGetUserInfo(e) {
    if(!this.data.username){
      wx.showModal({
        showCancel:false,
        content: '请填写用户名',
      })
      return;
    }

    if (!this.data.password) {
      wx.showModal({
        showCancel: false,
        content: '请填写密码',
      })
      return;
    }

    let that = this;
    console.log('用户信息', e.detail.userInfo)
    wx.setStorageSync('userInfo', e.detail.userInfo)

    let params = {
      username: that.data.username,
      password: that.data.password,
      vollege_id: app.globalData.vollege_id
    }

    util.apiRequest(AdminLogin, params).then(r => {
      console.log('登陆结果：', r)
      if (r.data.code == 0) {
        wx.showModal({
          showCancel: false,
          // title: '提示',
          content: r.data.info,
        })
      } else if (r.data.code == 1) {
        wx.showToast({
          title: r.data.info
        })
        wx.setStorageSync('adminInfo', r.data.data)
        wx.redirectTo({
          url: '/pages/index/index',
        })
      }
    })

  },

})